﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.sim {
    import flash.display.*;
    import Engine.Helpers.*;
    import Classes.*;
    import Transactions.*;
    import Classes.util.*;
    import Display.NeighborUI.*;
    import Classes.orders.*;

    public class FriendVisitMgrHelper {

        protected var m_friend:Player;
        protected var m_pick:FriendSlidePick;
        protected var m_active:Boolean = false;
        protected var m_delay:Number = 0;
        protected var m_friendOrder:VisitorHelpOrder = null;
        protected var m_friendOrderNdx:int = 0;
        protected var m_manager:FriendVisitManager = null;

        public function FriendVisitMgrHelper(_arg1:Player, _arg2:VisitorHelpOrder, _arg3:FriendVisitManager){
            if (_arg1){
                this.m_friendOrder = _arg2;
                this.m_friend = _arg1;
                this.m_manager = _arg3;
                this.m_pick = new FriendSlidePick(this.m_friend, this);
                this.showPick();
                this.movePickToNextObject(true);
            };
        }
        public function get pick():FriendSlidePick{
            return (this.m_pick);
        }
        public function get active():Boolean{
            return (this.m_active);
        }
        public function showPick():void{
            if (this.m_pick){
                GlobalEngine.viewport.hudBase.addChild(this.m_pick);
            };
        }
        public function hidePick():void{
            if (((this.m_pick) && (this.m_pick.parent))){
                this.m_pick.parent.removeChild(this.m_pick);
            };
        }
        public function closePick():void{
            if (((this.m_pick) && (this.m_pick.parent))){
                this.m_pick.closeInnerPane();
            };
        }
        public function acceptVisit(_arg1:FriendSlidePick):void{
            var _local4:Number;
            var _local5:MapResource;
            if (_arg1 != this.m_pick){
                return;
            };
            if (this.m_friendOrder == null){
                return;
            };
            this.m_active = true;
            this.doOnVisitReplayAction();
            var _local2:Array = this.m_friendOrder.getHelpTargets();
            if (_local2.length == 0){
                return;
            };
            var _local3:int;
            while (_local3 < _local2.length) {
                _local4 = _local2[_local3];
                _local5 = (Global.world.getObjectById(_local4) as MapResource);
                if (_local5 == null){
                } else {
                    _local5.lockForReplay();
                };
                _local3++;
            };
        }
        public function cancelVisit(_arg1:FriendSlidePick):void{
            if (_arg1 != this.m_pick){
                return;
            };
            GameTransactionManager.addTransaction(new TDeclineVisitorHelp(this.m_friendOrder));
            this.clearHighlightOnAllObjects();
            this.kill();
            this.m_manager.helperFinished(this);
        }
        public function showingSlide(_arg1:FriendSlidePick):void{
            var _local4:Number;
            var _local5:MapResource;
            if (_arg1 != this.m_pick){
                return;
            };
            if (this.m_friendOrder == null){
                return;
            };
            this.m_manager.closeAllPicks(this);
            var _local2:Array = this.m_friendOrder.getHelpTargets();
            var _local3:int;
            while (_local3 < _local2.length) {
                _local4 = _local2[_local3];
                _local5 = (Global.world.getObjectById(_local4) as MapResource);
                if (_local5 != null){
                    _local5.setVisitorInteractedHighlighted(true);
                };
                _local3++;
            };
        }
        public function panelClosed(_arg1:FriendSlidePick):void{
            if (!this.m_active){
                this.clearHighlightOnAllObjects();
            };
        }
        public function tweenToFinished(_arg1:FriendSlidePick):void{
            this.m_active = true;
            this.doOnVisitReplayAction();
        }
        public function moveToFront(_arg1:FriendSlidePick):void{
            var _local2:Sprite;
            if (_arg1){
                _local2 = GlobalEngine.viewport.hudBase;
                if (_local2.contains(_arg1)){
                    _local2.setChildIndex(_arg1, (_local2.numChildren - 1));
                };
            };
        }
        private function movePickToNextObject(_arg1:Boolean=false):Boolean{
            if (this.m_friendOrder == null){
                return (true);
            };
            var _local2:Array = this.m_friendOrder.getHelpTargets();
            if (_local2.length == 0){
                return (true);
            };
            if (this.m_friendOrderNdx >= _local2.length){
                return (true);
            };
            var _local3:Number = _local2[this.m_friendOrderNdx];
            while (this.m_friendOrder.isHelpTargetClaimed(_local3)) {
                this.m_friendOrderNdx++;
                if (this.m_friendOrderNdx >= _local2.length){
                    return (true);
                };
                _local3 = _local2[this.m_friendOrderNdx];
            };
            var _local4:MapResource = (Global.world.getObjectById(_local3) as MapResource);
            if (_local4 == null){
                return (false);
            };
            var _local5:Vector3 = _local4.getPosition();
            var _local6:Vector3 = _local4.getSize();
            _local5.x = (_local5.x + _local6.x);
            _local5.y = (_local5.y + _local6.y);
            if (_arg1){
                this.m_pick.setPosition(_local5.x, _local5.y);
            } else {
                this.m_pick.tweenToPos(_local5);
                this.m_active = false;
            };
            return (false);
        }
        public function kill():void{
            this.m_pick.kill(this.pick.cleanUp);
            this.m_pick = null;
            this.m_friendOrder = null;
            this.m_friend = null;
        }
        protected function doOnVisitReplayAction():void{
            if (this.m_friendOrder == null){
                return;
            };
            var _local1:Array = this.m_friendOrder.getHelpTargets();
            this.m_delay = 2;
            if (_local1.length == 0){
                return;
            };
            if (this.m_friendOrderNdx >= _local1.length){
                return;
            };
            var _local2:Number = _local1[this.m_friendOrderNdx];
            var _local3:MapResource = (Global.world.getObjectById(_local2) as MapResource);
            if (_local3 == null){
                return;
            };
            this.m_delay = _local3.onVisitReplayAction(new TRedeemVisitorHelpAction(this.m_friend.snUser.uid, _local2, _local3.getClassName(), _local3.getActionTargetName(), _local3.getVisitReplayEquivalentActionString()));
            this.m_friendOrder.claimHelpTarget(_local2);
            this.pick.tweenBounce();
        }
        protected function clearHighlightOnCurObject():void{
            if (this.m_friendOrder == null){
                return;
            };
            var _local1:Array = this.m_friendOrder.getHelpTargets();
            if (_local1.length == 0){
                return;
            };
            if (this.m_friendOrderNdx >= _local1.length){
                return;
            };
            var _local2:Number = _local1[this.m_friendOrderNdx];
            var _local3:MapResource = (Global.world.getObjectById(_local2) as MapResource);
            if (_local3 == null){
                return;
            };
            _local3.setVisitorInteractedHighlighted(false);
        }
        protected function clearHighlightOnAllObjects():void{
            var _local3:Number;
            var _local4:MapResource;
            if (this.m_friendOrder == null){
                return;
            };
            var _local1:Array = this.m_friendOrder.getHelpTargets();
            if (_local1.length == 0){
                return;
            };
            var _local2:int;
            while (_local2 < _local1.length) {
                _local3 = _local1[_local2];
                _local4 = (Global.world.getObjectById(_local3) as MapResource);
                if (_local4 == null){
                } else {
                    _local4.setVisitorInteractedHighlighted(false);
                };
                _local2++;
            };
        }
        public function update(_arg1:Number):void{
            if (!this.m_active){
                return;
            };
            if (this.m_delay > 0){
                this.m_delay = (this.m_delay - _arg1);
                return;
            };
            this.clearHighlightOnCurObject();
            this.m_friendOrderNdx++;
            var _local2:Boolean = this.movePickToNextObject();
            this.m_delay = 4;
            if (_local2){
                this.m_friendOrder.setStatus(VisitorHelpOrder.CLAIMED);
                this.kill();
                this.m_active = false;
                this.m_manager.helperFinished(this);
            };
        }

    }
}//package Classes.sim 
